
import { Provide, Inject } from '@midwayjs/core';
import { GradeDao } from '@dao/grade.dao';
import { CreateGradeDto, UpdateGradeDto, QueryGradeDto } from '@dto/grade.dto';
import { DownloadExcelService } from '../service/common/downloadExcel';
@Provide()
export class GradeService {
  @Inject()
  gradeDao: GradeDao;
  @Inject()
  downloadExcelService: DownloadExcelService;
   // 创建
  async create(body: CreateGradeDto) {
    return await this.gradeDao.create(body);
  }
  // 获取列表
  async list(query: QueryGradeDto) {
    return await this.gradeDao.list(query);
  }
  // 获取详情
  async detail(gradeId: string) {
    return await this.gradeDao.detail(+gradeId);
  }
  // 修改
  async update( body: UpdateGradeDto) {
    return await this.gradeDao.update(body);
  }
  // 删除
  async remove(gradeIds: Array<number>) {
    return await this.gradeDao.remove(gradeIds);
  }
  // 导出
  async export(queryParams: QueryGradeDto) {
    const headers = [
      { label: '年级ID', prop: 'gradeId' },
      { label: '学院ID', prop: 'deptId' },
      { label: '年级名称', prop: 'gradeName' },
      { label: '备注', prop: 'remark' },
      { label: '状态（0正常 1停用）', prop: 'status' }
    ];
    const { rows } = (await this.gradeDao.list(queryParams)).data;
    return this.downloadExcelService.downloadExcel({
      headers,
      data: rows,
      sheetName: 'Grade信息',
    });
  }
  //学院年级树
  async tree() {
    return await this.gradeDao.tree();
  }
}
